package com.cat.greedyAlgorithm;

import java.io.*;
import java.util.Arrays;
import java.util.zip.InflaterOutputStream;

/**
 * @author 曲大人的喵
 * @description https://www.luogu.com.cn/problem/P1809
 * @create 2025/10/8 21:14
 * @since JDK17
 */

public class Solution60 {
    static int N = ((int) (1e5 + 10));
    static int[] nums = new int[N];
    static int[] dp = new int[N];

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StreamTokenizer in = new StreamTokenizer(br);
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        in.nextToken();
        int n = ((int) in.nval);
        for (int i = 0; i < n; i++) {
            in.nextToken();
            nums[i] = ((int) in.nval);
        }
        Arrays.sort(nums, 0, n);
        if (n <= 1) {
            out.println(nums[0]);
            return;
        }
        if (n <= 2) {
            out.println(nums[1]);
            return;
        }
        dp[0] = nums[0];
        dp[1] = nums[1];
        dp[2] = nums[0] + nums[1] + nums[2];
        if (n <= 3) {
            out.println(dp[2]);
            return;
        }

        for (int i = 3; i < n; i++) {
            dp[i] = Math.min(
                    dp[i - 1] + nums[0] + nums[i],
                    dp[i - 2] + nums[i] + nums[1] + nums[0] + nums[1]
                    );
        }
        out.println(dp[n - 1]);

        br.close();
        out.flush();
        out.close();
    }
}
